package com.jk1123.us.common.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author huyoufu <https://github.com/huyoufu>
 * @TIME 2021-09-16 23:28
 * @description
 */
public class RequestUtil {
    private static final String USERAGENT_HEADER_NAME="User-Agent";
    private static final String REFERER_HEADER_NAME="referer";
    private static final String COOKIE_HEADER_NAME="cookie";


    public static String getReferer(){
        return getRequest().getHeader(REFERER_HEADER_NAME);
    }

    public static String getUserAgent(){

        return getRequest().getHeader(USERAGENT_HEADER_NAME);
    }
    public static String getRemoteIP(){
        return getRequest().getRemoteAddr();
    }
    public static String getCookie(){
        return getRequest().getHeader(COOKIE_HEADER_NAME);
    }

    public static HttpServletRequest getRequest(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
        return request;
    }
}
